package com.zzsy.shoppingpro.app;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.multidex.BuildConfig;
import android.support.multidex.MultiDexApplication;

import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.DefaultRefreshFooterCreator;
import com.scwang.smartrefresh.layout.api.DefaultRefreshHeaderCreator;
import com.scwang.smartrefresh.layout.api.RefreshFooter;
import com.scwang.smartrefresh.layout.api.RefreshHeader;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.footer.ClassicsFooter;
import com.scwang.smartrefresh.layout.header.ClassicsHeader;
import com.zzsy.shoppingpro.R;
import com.zzsy.shoppingpro.utils.CrashLog;
import com.zzsy.shoppingpro.utils.LogManager;

/**
 * Created by Administrator on 2019/8/16 0016.
 * 继承MultiDexApplication 解决65535问题
 * 全局公共类
 */

public class application extends MultiDexApplication {

    //设置全局上下文
    private static application app;
    private static String filePath;//应用统一存储路径

    static {
        //设置全局的header构造器
        SmartRefreshLayout.setDefaultRefreshHeaderCreator(new DefaultRefreshHeaderCreator() {
            @NonNull
            @Override
            public RefreshHeader createRefreshHeader(@NonNull Context context, @NonNull RefreshLayout layout) {
                layout.setPrimaryColorsId(R.color.bg_white,R.color.black);
                ClassicsHeader classicsHeader = new ClassicsHeader(context);
                classicsHeader.setEnableLastTime(false);
                return classicsHeader;
            }
        });
        //设置全局的Footer构造器
        SmartRefreshLayout.setDefaultRefreshFooterCreator(new DefaultRefreshFooterCreator() {
            @NonNull
            @Override
            public RefreshFooter createRefreshFooter(@NonNull Context context, @NonNull RefreshLayout layout) {
                ClassicsFooter classicsFooter = new ClassicsFooter(context);
                classicsFooter.setDrawableSize(20).setBackgroundColor(app.getResources().getColor(R.color.bg_white));
                return classicsFooter;
            }
        });
    }

    @Override
    public void onCreate() {
        super.onCreate();
        app = this;
        if(BuildConfig.DEBUG){
            LogManager.e(android.os.Process.myPid() + ":path = " + filePath);
            Thread.setDefaultUncaughtExceptionHandler(new CrashLog());
        }
    }

    public static application getApp(){
        return app;
    }

    public static String getFilePath(){
        return filePath;
    }
}
